import { UIComponent } from "../../mvc/ui_component";
import { UtilsInstance } from "../../shared/utils";
import { Player } from "../data/player";

export class PlayerItem extends UIComponent{
    player:Player;
    click_callback:VoidCallback;
    constructor(fairy_root){
        super(fairy_root);
    }

    SetPlayer(player:Player){
        this.player = player;
        if(this.player.is_me){
            this.GetGText("name").text = config.words["101"];
        }else{
            this.GetGText("name").text = this.player.user_name;
        }
        this.GetGText("card_num").text = "";

        this.GetGButton("click_btn").onClick(()=>{
            if(this.click_callback){
                this.click_callback();
            } 
        });
    }

    SetClickCallback(click_callback:VoidCallback){
        this.click_callback = click_callback;
    }

    Selected(is_select:boolean){
        if(is_select){
            this.SetScale(1.5, 1.5);
        }else{
            this.SetScale(1.0, 1.0);
        }
    }

    UpdateInfo(){
        this.GetGText("card_num").text = UtilsInstance.formatString(config.words["102"], this.player.card_type_list.length);
    }

    DeleteMe(){
        
    }
}